package thinkinjava4.ch13_strings;

import java.util.Arrays;

public class Splitting {
    public static String knights = "Then, when you have found the shrubbery, you must cut down the mightiest tree in the forest... with... a herring!";

    public static void split(String regex) {
        System.out.println(Arrays.toString(knights.split(regex)));
    }

    public static void main(String[] args) {
        split(" ");
        // \W等价于[^A-Za-z_0-9]  非单词字符
        split("\\W+");
        split("n\\W+");
        // \D等价于[^0-9]
        System.out.println("123是数字：" + "123".matches("\\d+"));
        System.out.println("123是数字：" + "123".matches("[0-9]+"));
        System.out.println("abc是非数字：" + "abc".matches("\\D+"));
        System.out.println("abc是非数字：" + "abc".matches("[^0-9]+"));
    }
}
